import { Token } from '@/types/data'
const TOKEN_KEY = 'itcast_geek_mobile'
// 获取token
const getToken = (): Token => {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}')
}
// 设置token
const setToken = (data: Token): void =>
  localStorage.setItem(TOKEN_KEY, JSON.stringify(data))
// 移除token
const clearToken = (): void => localStorage.removeItem(TOKEN_KEY)
// 判断授权
const hasToken = (): boolean => !!getToken().token

export { hasToken, getToken, setToken, clearToken }
